package com.huawei.od.c.easy.t2;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class T2 {

    public static void main(String[] args) {
        int[] arr1 = {0, 5, 8, 9, 9, 10};
        int[] arr2 = {5, 0, 9, 9, 9, 8};
        int[] arr3 = {5, 0, 6, 0,7,0};
        t2(arr1, arr2);
        t2(arr3, arr3);
    }

    /**
     * 分别计算 arr1  arr2 的气
     *
     * @param arr1
     * @param arr2
     */
    private static void t2(int[] arr1, int[] arr2) {
        System.out.println(doCountQI(arr1));
        System.out.println(doCountQI(arr2));
    }

    private static int doCountQI(int[] arr) {
        String MID = ",";
        Set<String> set = new HashSet<>();
        Map<String, Integer> map = new HashMap<>();
        for (int i = 0; i < arr.length - 1; i += 2) {
            int h = arr[i];
            int v = arr[i + 1];
            set.add((h - 1) + MID + v);
            set.add((h + 1) + MID + v);
            set.add(h + MID + (v - 1));
            set.add(h + MID + (v + 1));

            map.put(h + MID + v, 0);
        }
        int ans = set.size();
        for (String next : set) {
            String[] split = next.split(MID);
            int h = Integer.parseInt(split[0]);
            int v = Integer.parseInt(split[1]);
            if (h < 0 || h > 18 || v < 0 || v > 18 || map.containsKey(next)) {
                ans--;
            }
        }
        return ans;
    }
}
